<?php
class banner{
	//banner selcction function
	function selectBanner()
	{
		global $con;
		$sql="select * from tbl_banner ";
		$res = mysqli_query($con,$sql);
		return $res;
	}/// EOF
	
	
	//function for adding banner
		function insertBanner($name,$image,$status,$date)
	{
			//echo $status; exit;
			
		global $con;
		$sql=sprintf("INSERT INTO tbl_banner SET
							banner_name='%s',
							banner_image='%s',
							banner_status='%s',
							banner_added_date='%s'",
							mysqli_escape_string($con,$name),
							mysqli_escape_string($con,$image),
							mysqli_escape_string($con,$status),
							mysqli_escape_string($con,$date));
							
		$res = mysqli_query($con,$sql);
		
		//var_dump($res);die;
		return $res;
	}/// EOF
	
	//function for updating banner
	function updateBanner($id,$name,$image,$status,$date){
		
		global $con;
		
		$sql=sprintf("UPDATE tbl_banner set 
						banner_name='%s',
							banner_image='%s',
							banner_status='%s',
							banner_added_date='%s' where banner_id='%d'",
							mysqli_escape_string($con,$name),
							mysqli_escape_string($con,$image),
							mysqli_escape_string($con,$status),
							mysqli_escape_string($con,$date),
							mysqli_escape_string($con,$id));	
		$res = mysqli_query($con,$sql);
		if(!$res){
			echo "Banner not Added";
			die("Sql error " . mysqli_error($con));
			
		}
		echo "successfully Added";
		return $res;	
		
	
	}
	//function for deleting banner
	function deleteBanner($id)
	{
		global $con;
		$sql="DELETE FROM tbl_banner WHERE banner_id='$id' ";
		mysqli_query($con,$sql);
	}
	
	//function selecting images from table
	
	function selectimage(){
		global $con;
		$sql= "select banner_image from tbl_banner";
		$res= mysqli_query($con,$sql);
		return $res;
		
	}
	
	//function selecting item by id
	
	function selectBannerById($id){
		global $con;
		$sql= "select * from tbl_banner where banner_id='$id'";
		$res= mysqli_query($con,$sql);
		return $res;
	}
	
	function bannerStatus($status,$bannerId)
	{
		global $con;
		$sql="update tbl_banner SET banner_status='$status' WHERE banner_id='$bannerId'";
		mysqli_query($con,$sql);
	}
	
	function successmsg(){
		echo "<span class='successmsg'>edited successully</span>";
	}
	
	// selects banner if ststus is set
	function selectBannerByStatus(){
		global $con;
		$sql= "select banner_image from tbl_banner where banner_status='y'";
		$res= mysqli_query($con,$sql);
		return $res;
	}

}	


$objBanner=new banner();
?>
